<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      // stepsConfig: {
      //   steps: [
      //     {
      //       title: '步骤1',
      //       Attrs: ['productNo', 'modelNo','modelId',  'clientId']
      //     },
      //     {
      //       title: '步骤2',
      //       Attrs: ['productCategoryId', 'productWeight', 'weightScope', 'productVolume', 'volumeScope', 'volumeRemark',
      //         'bottleInDiameter', 'bottleOutDiameter','bottleLength','bottleWeight', 'headNeckHeight', 'bottleHeight', 'lengthWeightHeight',
      //         'productQuestion', 'productAssort', 'deepCategoryList', 'remark']
      //     },
      //     {
      //       title: '步骤3'
      //     }
      //   ]
      // },
      screenshotUpload: true,
      dataFormConfig: {
        id: {
          hidden: true
        },
        productNo: {
          label: '产品型号',
          placeholder: '请输入产品型号'
        },
        unitPrice: {label: '裸瓶价格', type: 'number'},


        productVolume: {
          label: '容量(ml)',
          type: 'number',
          max: 1000,
          default: 0
        },
        productWeight: {
          label: '克重(g)',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleOutDiameter: {
          label: '口径',
          placeholder: '请输入瓶口外径',
          default: "15口"
        },
        boxPackingQuantity: { label: '装箱数量', type: 'number' },
        grossWeight: { label: '毛重',       type: 'number' },
        boxCartonSize: { label: '箱规(cm)' },
        relateSize:{
          label: '尺寸',
          placeholder: '请输入尺寸'
        },
        headNeckHeight: {
          label: '头高(mm)',
          type: 'number',
          max: 1000,
          default: 0
        },
        productImageId: {
          label: '产品图片',
          type: 'uploadScreenshot',
          imageType: 'uploadProductImage'
        },
        productDrawingId: {
          label: '产品图纸',
          type: 'uploadImage',
          imageType: 'uploadProductPaper'
        },
        remark: {
          label: '产品备注',
          inputType: 'textarea',
          placeholder: '请输入产品备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    addNewModel() {
      const cb = (newValue) => {
        this.initModelInfoList('modelId')
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
    init(id, property, cb) {
      this.dataForm.id = id || 0
      /**
       * 1  裸瓶
       * 2  盖子
       * 3  喷头
       * 4  中套
       * 5  披肩
       * 99  其他
       * @type {number}
       */
      this.dataForm.productCategoryId = 1

   //   this.initProductCategoryList()
   //   this.initDeepCategoryList('deepCategoryList')
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('productNo', 'status', 'productWeight', 'productVolume', 'bottleLength', 'bottleWeight', 'bottleHeight', 'bottleOutDiameter'),
        initApi: 'productApi/productInfoInfo',
        saveApi: 'productApi/saveProductInfo',
        updateApi: 'productApi/updateProductInfo',
        objectName: 'productInfo',
        submitCallback: cb,
        screenshotUploadFlag: true
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            if (key.startsWith('clientId')) {
              this.dataForm['clientId'] = property[key].clientId
            }else {
              this.dataForm[key] = property[key]
            }
          })
        }
      })
    }
  }
}
</script>
